package com.yanqu.road.dao.impl.log;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.db.DbParameter;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.log.LogRecharge;

import java.sql.Timestamp;
import java.sql.Types;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class LogRechargeDaoImpl extends TempDao {

	public boolean addLogRechargeList(List<LogRecharge> list) {
		boolean result = false;
		getDb().setConnName(DbNameStrategy.getServerDb());
		String sql = "INSERT INTO t_s_recharge_detail(userId,mallId,num,time,orderNo,price,serverId,type,sdkOrderNo,vipExp,acttype,currency," +
				"realMoney,realCurrency,localMoney,localCurrency,ltrRate,newMoney,tax,productCoin,device,payChannel,platformOrderNo,orderType," +
				"activityId,couponMoney,mallMarkId,isRepeatBuy) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
		List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
		for (LogRecharge info : list) {
			Map<Integer, DbParameter> para = new HashMap<>();
			int i = 1;
			para.put(i++, new DbParameter(Types.BIGINT, info.getUserId()));
			para.put(i++, new DbParameter(Types.INTEGER, info.getMallId()));
			para.put(i++, new DbParameter(Types.INTEGER, info.getNum()));
			para.put(i++, new DbParameter(Types.TIMESTAMP, new Timestamp(info.getTime())));
			para.put(i++, new DbParameter(Types.VARCHAR, info.getOrderNo()));
			para.put(i++, new DbParameter(Types.BIGINT, info.getPrice()));
			para.put(i++, new DbParameter(Types.BIGINT, info.getServerId()));
			para.put(i++, new DbParameter(Types.INTEGER, info.getType()));
			para.put(i++, new DbParameter(Types.VARCHAR, info.getSdkOrderNo()));
			para.put(i++, new DbParameter(Types.BIGINT, info.getVipExp()));
			para.put(i++, new DbParameter(Types.VARCHAR, info.getActivityType()));
			para.put(i++, new DbParameter(Types.VARCHAR, info.getCurrency()));
			para.put(i++, new DbParameter(Types.VARCHAR, info.getRealMoney()));
			para.put(i++, new DbParameter(Types.VARCHAR, info.getRealCurrency()));
			para.put(i++, new DbParameter(Types.VARCHAR, info.getLocalMoney()));
			para.put(i++, new DbParameter(Types.VARCHAR, info.getLocalCurrency()));
			para.put(i++, new DbParameter(Types.VARCHAR, info.getLtrRate()));
			para.put(i++, new DbParameter(Types.VARCHAR, info.getNewMoney()));
			para.put(i++, new DbParameter(Types.VARCHAR, info.getTax()));
			para.put(i++, new DbParameter(Types.BIGINT, info.getProductCoin()));
			para.put(i++, new DbParameter(Types.INTEGER, info.getDevice()));
			para.put(i++, new DbParameter(Types.VARCHAR, info.getPayChannel()));
			para.put(i++, new DbParameter(Types.VARCHAR, info.getPlatformOrderNo()));
			para.put(i++, new DbParameter(Types.INTEGER, info.getOrderType()));
			para.put(i++, new DbParameter(Types.INTEGER, info.getActivityId()));
			para.put(i++, new DbParameter(Types.VARCHAR, info.getCouponMoney()));
			para.put(i++, new DbParameter(Types.INTEGER, info.getMallMarkId()));
			para.put(i++, new DbParameter(Types.BOOLEAN, info.isRepeatBuy()));
			mapList.add(para);
		}

		if (getDb().executeBatchQuery(sql, mapList) > -1) {
			result = true;
		}
		return result;
	}
}
